// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================

package tc.crase.app;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.security.auth.login.Configuration;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

import tc.common.utility.TcCmd;
import tc.crase.view.ViewRoot;

public class CraseApp {
	public static void main(String args[]) {
		Configuration cfg;
		cfg = Configuration.getConfiguration();
		
		Font labelFont = UIManager.getFont("Label.font");
		UIManager.put("Label.font", new Font(labelFont.getName(), Font.PLAIN, labelFont.getSize()));
		
		Font buttonFont = UIManager.getFont("Button.font");
		UIManager.put("Button.font", new Font(buttonFont.getName(), Font.PLAIN, buttonFont.getSize()));

		Font listFont = UIManager.getFont("List.font");
		UIManager.put("List.font", new Font(listFont.getName(), Font.PLAIN, listFont.getSize()));
		
		Font radioFont = UIManager.getFont("RadioButton.font");
		UIManager.put("RadioButton.font", new Font(radioFont.getName(), Font.PLAIN, radioFont.getSize()));

		Font checkFont = UIManager.getFont("CheckBox.font");
		UIManager.put("CheckBox.font", new Font(checkFont.getName(), Font.PLAIN, checkFont.getSize()));

		Color b = UIManager.getColor("controlShadow");
		Color background = new Color( b.getRed()  +(255-b.getRed())/2,
				                      b.getGreen()+(255-b.getGreen())/2,
				                      b.getBlue() +(255-b.getBlue())/2 );
		
		UIManager.put("FileChooser.readOnly", Boolean.TRUE);
		
		ViewRoot.initialize();
		TcCmd.SIDEBAR_WIDTH = 160;
		TcCmd.COMPONENT_WIDTH = 160;
		
		//<STEP>Main application window
		JFrame.setDefaultLookAndFeelDecorated(true);
		JFrame mainFrame;
		mainFrame = new JFrame();
		mainFrame.setTitle("Crase");
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.setLocation(150, 200);
				
		ViewRoot.pane.setBackground(background);
		ViewRoot.pane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		mainFrame.getContentPane().add(ViewRoot.pane, BorderLayout.CENTER);
				
		//<STEP>Toolbar
		Toolbar toolBar = new Toolbar();
		toolBar.setFont(new Font(toolBar.getFont().getName(), Font.PLAIN, toolBar.getFont().getSize()));
		mainFrame.getContentPane().add(toolBar, BorderLayout.NORTH);
		ImageIcon icon = new ImageIcon(toolBar.getClass().getResource("images/app.png"));
		mainFrame.setIconImage(icon.getImage());
				
		JPanel border = new JPanel();
		border.setMaximumSize(new Dimension(TcCmd.SIDEBAR_WIDTH+20,10000));
		border.setMinimumSize(new Dimension(TcCmd.SIDEBAR_WIDTH+20,100));
		border.setPreferredSize(new Dimension(TcCmd.SIDEBAR_WIDTH+20,600));
		border.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.GRAY));
		mainFrame.getContentPane().add(border, BorderLayout.WEST);
		
		TcCmd.dialog.setLayout(new BoxLayout(TcCmd.dialog, BoxLayout.Y_AXIS));
		TcCmd.dialog.setMaximumSize(new Dimension(TcCmd.SIDEBAR_WIDTH,10000));
		TcCmd.dialog.setMinimumSize(new Dimension(TcCmd.SIDEBAR_WIDTH,100));
		TcCmd.dialog.setPreferredSize(new Dimension(TcCmd.SIDEBAR_WIDTH,600));
		
		border.add(TcCmd.dialog);
		
	    //<STEP>Show it all
		mainFrame.pack();
	    mainFrame.setVisible(true);
	}
}
